<?php
/**
 * Klasse zum erstellen eines Dropdown Eintrags
 *
 * @author		Joachim Ruf, Loresoft Software (http://www.loresoft.de)
 * @license		New BSD License
 * @version		Class for Bootstrap v2.3.2
 *
 * */


Class Bootstrap_Dropdown_Entry
{
	private $arrList			= array();
	private $active				= false;
	private $content			= NULL;
	private $arrParam			= NULL;


	/**
	 * @param string $_size		: breite {1-12}
	 * @param string $_content	: Auszugebender Content
	 * */
	function __construct ($_content = NULL, array $_arrParam = array()) {
		if (!isset($_arrParam['href'])) {
			$_arrParam['href']	= '#';
		}

		$this->content	= $_content;
		$this->arrParam	= $_arrParam;
	}


	private function getParameter ($_class, array $_arrParam) {
		$result	= NULL;

		if (isset($_arrParam['class'])) { // Class-Parameter verbinden
			$_arrParam['class']	= $_arrParam['class'].' '.$_class;
		} else {
			$_arrParam['class']	= $_class;
		}

		foreach ($_arrParam as $key => $val) {
			$result	.= ' '.$key.'="'.$val.'"';
		}

		return $result;
	}


	public function setActive($_enable = true) {
		$this->active	= $_enable;
	}


	/**
	 * Liefert den Content zurueck
	 * @return int
	 * */
	public function getContent() {
		return $this->content;
	}


	/**
	 * Erstellt eine Subliste
	 * @param string $_content	: Auszugebender Content
	 * @param array	$_arrParam	: array('href' => 'url', 'title' => 'Title-Text', 'rel' => 'follow|nofollow|..')
	 * @return Bootstrap_Dropdown_Entry
	 * */
	public function addSubentry($_content, array $_arrParam = array()) {
		return $this->arrList[]	= new Bootstrap_DropDown_Entry($_content, $_arrParam);
	}


	/**
	 * @desc Gibt den Datensatz aus.
	 * @return string
	 * */
	public function display() {
		$result	= NULL;

		$active	= ($this->active === true) ? 'active' : '';

		if (count($this->arrList)) {
			/* @var $oObject Bootstrap_DropDown_Entry */
			foreach ($this->arrList as $Key => $oObject) {
				$result	.= $oObject->display();
			}

			return '<li class="dropdown-submenu '.$active.'">
						<a'.$this->getParameter(''.$active, $this->arrParam).'>'.$this->content.'</a>
						<ul class="dropdown-menu">
							'.$result.'
						</ul>
					</li>';
		} else {
			return '<li class="'.$active.'"><a'.$this->getParameter('', $this->arrParam).'>'.$this->content.'</a></li>';
		}

	}


}


?>